home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
program
/
ctlib100.zip
/
INSTALL.LZH
/
CTBTREES.INT
< prev
next >
Wrap
Text File
|
1996-10-12
|
7KB
|
164 lines
{**************************************************************************}
{* BitSoft Development, L.L.C. *}
{* Copyright (C) 1995, 1996 BitSoft Development, L.L.C. *}
{* All rights reserved. *}
{* BTree objects unit *}
{* Version 1.2.0 *}
{**************************************************************************}
unit ctBTrees;
{$X+,B-}
interface
uses Objects,
{$ifdef ver60} BsdVer60, {$endif}
Containr, ctTrees, ctStacks;
type
PmWayNode = ^TmWayNode;
TmWayNode = object(TNode)
ID : LongInt;
Owner : Pointer;
Count : Word;
Data : PChar;
Modified : Boolean;
constructor Init (AOwner : Pointer);
destructor Done; virtual;
procedure AtCopyBlock(Index, SourceIndex : Word; SourceNode : PmWayNode;
ItemCount : Word; Larger : Boolean);
procedure AtDelete(Index: Word; Larger : Boolean);
procedure AtDeleteBlock(Index, ItemCount : Word; Larger : Boolean);
procedure AtInsert(Index : Word; Item : Pointer; Subtree : LongInt;
Larger : Boolean);
function AtItem (Index : Word) : Pointer; virtual;
procedure AtPutItem (Index : Word; Item : Pointer); virtual;
procedure AtPutSubTree (Index : Word; SubTree : LongInt);
function AtSubTree (Index : Word) : LongInt;
procedure FreeAll; virtual;
procedure Insert (Item : Pointer; ChildNode : LongInt);
function IsFull : Boolean;
function GetKey(Item : Pointer) : Pointer; virtual;
function LoadData (AOffset : LongInt): Boolean; virtual;
function Search (Key : Pointer; var Index : Word) : Boolean; virtual;
function StoreData: Boolean; virtual;
end; { TmWayNode }
type
PBaseBTree = ^TBaseBTree;
TBaseBTree = object(TStreamTree)
DataSize : Word;
NodeDataSize : Word;
MaxItems : Word;
CurrentNode : PmWayNode;
ParentStack : PArrayStack;
ChildIndex : LongInt;
FreeNodes : LongInt;
Version : Word;
TempItem : Pointer;
NodeBuffer : PCollection;
NodeBufferSize : LongInt;
constructor Init (AStream : PStream; ADegree, ADataSize, ANodeDataSize,
FileVersion : Word; ANodeBufferSize : LongInt);
constructor Open (AStream : PStream; ANodeBufferSize : LongInt);
destructor Done; virtual;
procedure AgeNode(Node : PmWayNode);
procedure ClearStack;
function Concatenate : Boolean;
function CopyItem(Item, Dest : Pointer) : Pointer; virtual;
function Degree : Word; virtual;
procedure Flush; virtual;
procedure FreeItem (Item : Pointer); virtual;
function GetNewNode : PmWayNode;
procedure GetNode (ID : LongInt);
function ItemPut (OldItem, NewItem : Pointer) : Boolean; virtual;
function ItemsMatch(Item1, Item2 : Pointer) : Boolean; virtual;
function KeyOf(Item : Pointer) : Pointer; virtual;
function NewNode : PmWayNode; virtual;
function NodeStoredSize : Word; virtual;
procedure PopNode;
procedure PushNode (ChildNode : LongInt; AChildIndex : Word);
procedure Redistribute(Source, Target, Parent : PmWayNode; SplitIndex,
ItemsToMove : Word; MoveToLeft : Boolean);
function RedistributeEmpty : Boolean;
function RedistributeFull (Item : Pointer) : Boolean;
procedure ReleaseNode (Node : PmWayNode);
function Split(var Item : Pointer; var ChildNode : LongInt) : Boolean;
procedure Update;
end; { TBaseBTree }
const
TBTreeSig : array [0..6] of Char = 'ctBTree';
const
TBTreeVer = $0100;
type
PBTree = ^TBTree;
TBTree = object(TBaseBTree)
constructor Init (ADegree, ADataSize : Word; AStream : PStream;
ABufferSize : LongInt);
constructor Open (AStream : PStream; ABufferSize : LongInt);
destructor Done; virtual;
function Delete (Item : Pointer) : Boolean; virtual;
function DeleteAll : Boolean; virtual;
function DeleteAllThat (Test: Pointer): Boolean; virtual;
function Find (Key : Pointer; var Hits : LongInt) : Boolean;
virtual;
function FindThat (Key, Test : Pointer; var Hits : LongInt) :
Boolean; virtual;
function First : Pointer; virtual;
function FirstThat (Test : Pointer) : Pointer; virtual;
function ForEach (Action: Pointer): Boolean; virtual;
function ForEachThat (Test, Action : Pointer): Boolean; virtual;
function FreeAll : Boolean; virtual;
function FreeAllThat (Test: Pointer): Boolean; virtual;
function Height : Word; virtual;
function Insert (Item : Pointer) : Boolean; virtual;
function ItemReplace (OldItem, NewItem : Pointer) : Boolean; virtual;
function KeyFirst (Key : Pointer) : Pointer; virtual;
function KeyLast (Key : Pointer) : Pointer; virtual;
function Last : Pointer; virtual;
function LastThat(Test : Pointer) : Pointer; virtual;
function Next (Item : Pointer) : Pointer; virtual;
function NextThat(Test : Pointer; Item : Pointer) : Pointer; virtual;
function Prev (Item : Pointer) : Pointer; virtual;
function PrevThat(Test : Pointer; Item : Pointer) : Pointer; virtual;
private
DuplicatesStack : PArrayStack;
function LocateItem (Item : Pointer; var Index : Word) : Boolean;
function LocateFirst (Key : Pointer; var Index : Word) : Boolean;
function LocateLast (Key : Pointer; var Index : Word) : Boolean;
procedure ReadHeader; virtual;
function ValidSignature (ASignature : PChar) : Boolean;
function ValidVersion (AVersion : Word) : Boolean;
procedure WriteHeader; virtual;
end; { TBTree }
type
PObjectBTree = ^TObjectBTree;
TOBjectBTree = object(TBTree)
constructor Init (ADegree, ADataSize : Word; AStream : PStream;
ABufferSize : LongInt);
procedure FreeItem (Item : Pointer); virtual;
function GetItem (var S : TStream) : Pointer; virtual;
function NewNode : PmWayNode; virtual;
procedure PutItem (var S : TStream; Item : Pointer); virtual;
private
function NodeStoredSize : Word; virtual;
end; { TObjectBTree }
type
PmWayObjectNode = ^TmWayObjectNode;
TmWayObjectNode = object(TmWayNode)
function AtItem (Index : Word) : Pointer; virtual;
procedure AtPutItem (Index : Word; Item : Pointer); virtual;
procedure FreeAll; virtual;
function LoadData (AOffset : LongInt): Boolean; virtual;
function StoreData: Boolean; virtual;
end; { TmWayObjectNode }
implementation
end.